package com.ruoyi.web.controller.student;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.TTeacherInfo;
import com.ruoyi.system.service.ITTeacherInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 老师信息Controller
 *
 * @author xiyu
 * @date 2024-12-08
 */
@RestController
@RequestMapping("/student/teacher")
public class TTeacherInfoController extends BaseController {
    @Autowired
    private ITTeacherInfoService tTeacherInfoService;

    /**
     * 查询老师信息列表
     */
    @PreAuthorize("@ss.hasPermi('student:teacher:list')")
    @GetMapping("/list")
    public TableDataInfo list(TTeacherInfo tTeacherInfo) {
        startPage();
        List<TTeacherInfo> list = tTeacherInfoService.selectTTeacherInfoList(tTeacherInfo);
        return getDataTable(list);
    }

    /**
     * 导出老师信息列表
     */
    @PreAuthorize("@ss.hasPermi('student:teacher:export')")
    @Log(title = "老师信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TTeacherInfo tTeacherInfo) {
        List<TTeacherInfo> list = tTeacherInfoService.selectTTeacherInfoList(tTeacherInfo);
        ExcelUtil<TTeacherInfo> util = new ExcelUtil<TTeacherInfo>(TTeacherInfo.class);
        util.exportExcel(response, list, "老师信息数据");
    }

    /**
     * 获取老师信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('student:teacher:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(tTeacherInfoService.selectTTeacherInfoById(id));
    }

    /**
     * 新增老师信息
     */
    @PreAuthorize("@ss.hasPermi('student:teacher:add')")
    @Log(title = "老师信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TTeacherInfo tTeacherInfo) {
        tTeacherInfo.setCreateBy(getUsername());
        return toAjax(tTeacherInfoService.insertTTeacherInfo(tTeacherInfo));
    }

    /**
     * 修改老师信息
     */
    @PreAuthorize("@ss.hasPermi('student:teacher:edit')")
    @Log(title = "老师信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TTeacherInfo tTeacherInfo) {
        return toAjax(tTeacherInfoService.updateTTeacherInfo(tTeacherInfo));
    }

    /**
     * 删除老师信息
     */
    @PreAuthorize("@ss.hasPermi('student:teacher:remove')")
    @Log(title = "老师信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids, @PathVariable String teacherStatus) {
        return toAjax(tTeacherInfoService.deleteTTeacherInfoByIds(ids, teacherStatus));
    }
}
